package com.weiyuwqj.server.service.account.service.impl;

import com.github.pagehelper.PageHelper;
//import com.weiyuwqj.api.hengfeng.model.base.HfBaseResponseBean;
//import com.weiyuwqj.api.hengfeng.model.liquidate.HfLiquidateFundData;
//import com.weiyuwqj.api.hengfeng.model.liquidate.HfLiquidateBalanceInfo;
import com.weiyuwqj.api.model.vo.BalanceInfoVo;
import com.weiyuwqj.api.model.vo.FundData;
import com.weiyuwqj.api.util.DateUtils;
import com.weiyuwqj.api.util.StringUtils;
import com.weiyuwqj.server.mapper.BusAccountCashMapper;
import com.weiyuwqj.server.mapper.BusAccountRechargeMapper;
//import com.weiyuwqj.server.pay.LiquidateApi;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import com.weiyuwqj.server.mapper.BusAccountMapper;
import com.weiyuwqj.api.service.BusAccountService;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.BusAccount;
import com.weiyuwqj.api.model.BusItemInvest;
import com.weiyuwqj.api.model.vo.BusAccountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("accountService")
public class BusAccountServiceImpl extends BaseServiceImpl<BusAccount>
        implements BusAccountService {

    @Autowired
    private BusAccountMapper busAccountMapper;

    @Autowired
    private BusAccountRechargeMapper rechargeMapper;

    @Autowired
    private BusAccountCashMapper accountCashMapper;

//    @Autowired
//    private LiquidateApi liquidateApi;


    @Override
    public BusAccount getBusAccountByUserId(int userId) {
        return busAccountMapper.getBusAccountByUserId(userId);
    }

    @Override
    public PageList getList(Paginator p, Map<String, Object> param) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        List<BusAccountVo> list = busAccountMapper.getList(param);
        return new PageList(list);
    }

    //后台不分页列表
    @Override
    public List<BusAccountVo> getList(Map<String, Object> param) {
        return busAccountMapper.getList(param);
    }

    @Override
    public int update(BusAccount newAccount, BusItemInvest oldAccount) {
        return 0;
    }


    @Override
    public List<BusAccountVo> excelList(Map<String, Object> param) {
        return busAccountMapper.getList(param);
    }

    @Override
    public Map<String, Object> statAccount(Map map) {
        return busAccountMapper.statAccount(map);
    }

    @Override
    public PageList listByGuaranteeId(Paginator p, Map<String, Object> map) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        List<BusAccountVo> list = busAccountMapper.listByGuaranteeId(map);
        return new PageList(list);
    }

    @Override
    public Map sumInvestAmount() {
        return busAccountMapper.sumInvestAmount();
    }

//    @Override
//    public List<FundData> checkOrders() {
//        Map map = new HashMap();
//        Date beginTime = DateUtils.getLastDayBeginTime();
//        Date endTime = DateUtils.getLastDayEndTime();
//        map.put("beginTime", beginTime);
//        map.put("endTime", endTime);
//        map.put("status", 1);
//        List<FundData> rechargeList = rechargeMapper.listFundData(map);
//        List<FundData> cashList = accountCashMapper.listFundData(map);
//        rechargeList.addAll(cashList); //将充值提现合并
//
//        //调恒丰接口
//        HfLiquidateFundData liquidateFundData = new HfLiquidateFundData();
//        liquidateFundData.setPaycheck_date(DateUtils.formatDate(new Date(), "yyyyMMdd"));
//        liquidateFundData.setBegin_time(DateUtils.formatDate(beginTime, "yyyyMMddHHmmss"));
//        liquidateFundData.setEnd_time(DateUtils.formatDate(endTime, "yyyyMMddHHmmss"));
//        liquidateFundData.setPrecheck_flag("1");
//        liquidateFundData.setOrder_no(StringUtils.getOrderNo());
//        String response = liquidateApi.fundData(liquidateFundData);
//
//        String[] orderList = response.split("\\n");
//        List<FundData> fundDatas = new ArrayList<>(orderList.length);
//        for (int i = 0; i < orderList.length; i++) {
//            String[] propertyList = orderList[i].split("\\|");
//            FundData fundData = new FundData();
//            if (i == 0) {
//                fundData.setAmount(propertyList[3]);
//                fundData.setType("总和");
//            } else {
//                fundData.setAmount(propertyList[4]);
//                fundData.setOrderNo(propertyList[3]);
//                fundData.setType(propertyList[5]);
//            }
//            fundDatas.add(fundData);
//        }
//
//        //去除重复项
//        rechargeList.removeAll(fundDatas);
//        fundDatas.removeAll(rechargeList);
//        fundDatas.addAll(rechargeList);
//        return fundDatas;
//    }

//    @Override
//    public List<BalanceInfoVo> checkAccount() {
//        Map map = new HashMap();
//        Date beginTime = DateUtils.getLastDayBeginTime();
//        Date endTime = DateUtils.getLastDayEndTime();
//        map.put("beginTime", beginTime);
//        map.put("endTime", endTime);
//        map.put("realNameStatus", 1);
//        List<BalanceInfoVo> accountList = busAccountMapper.listBalanceInfo(map);
//
//        HfLiquidateBalanceInfo balanceInfo = new HfLiquidateBalanceInfo();
//        balanceInfo.setPaycheck_date(DateUtils.formatDate(new Date(), "yyyyMMdd"));
//        balanceInfo.setBegin_time(DateUtils.formatDate(beginTime, "yyyyMMddHHmmss"));
//        balanceInfo.setEnd_time(DateUtils.formatDate(endTime, "yyyyMMddHHmmss"));
//        balanceInfo.setPrecheck_flag("1");
//        balanceInfo.setOrder_no(StringUtils.getOrderNo());
//        String response = liquidateApi.doLiquidateBalanceInfo(balanceInfo);
//
//        String[] orderList = response.split("\\n");
//        List<BalanceInfoVo> balanceInfoList = new ArrayList<>(orderList.length);
//        for (int i = 0; i < orderList.length-1; i++) {
//            String[] propertyList = orderList[i].split("\\|");
//            BalanceInfoVo balanceInfoVo = new BalanceInfoVo();
//            if (i == 0) {
//                balanceInfoVo.setTotal(propertyList[2]);
//                balanceInfoVo.setFrozen(propertyList[4]);
//                balanceInfoVo.setUsable(propertyList[3]);
//            } else {
//                balanceInfoVo.setTotal(propertyList[3]);
//                balanceInfoVo.setFrozen(propertyList[5]);
//                balanceInfoVo.setUsable(propertyList[4]);
//                balanceInfoVo.setPlatformId(propertyList[2]);
//            }
//            balanceInfoList.add(balanceInfoVo);
//        }
//
//        //去除重复项
//        accountList.removeAll(balanceInfoList);
//        balanceInfoList.removeAll(accountList);
//        accountList.addAll(balanceInfoList);
//        return accountList;
//    }



}

